package com.chinaisafe.demo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.validated.UpdateGroup;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.demo.vo.request.DemoTableReqVO;
import com.chinaisafe.demo.vo.response.DemoTableRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.demo.service.DemoTableService;
import org.springframework.web.bind.annotation.RestController;

/**
 * DemoTableController
 * Description：测试类接口层
 *
 * @author JiangZhaoYong
 * @date  2024-07-15 13:00:14
 */
@RestController
@RequestMapping("/demoTable")
@Tag(name = "测试类接口层", description = "测试类接口层")
public class DemoTableController {

    @Autowired
    private DemoTableService demoTableService;

    @GetMapping("/pageList")
    @Operation(summary = "获取测试类分页列表", description = "获取测试类分页列表")
    public Answer<IPage<DemoTableRespVO>> pageList(DemoTableReqVO demoTableReqVO) {
        IPage<DemoTableRespVO> pageList = demoTableService.getPageList(demoTableReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增测试类", description = "新增测试类")
    @OperationLog(title = "测试类-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<DemoTableRespVO> add(@RequestBody @Validated(AddGroup.class) DemoTableReqVO demoTableReqVO) {
        DemoTableRespVO demoTableRespVO = demoTableService.add(demoTableReqVO);
        return Answer.success("保存成功", demoTableRespVO);
    }

    @PutMapping()
    @Operation(summary = "根据id编辑测试类", description = "根据id编辑测试类")
    @OperationLog(title = "测试类-根据id编辑", businessType = BusinessTypeEnum.UPDATE)
    public Answer<DemoTableRespVO> update(@RequestBody @Validated(UpdateGroup.class) DemoTableReqVO demoTableReqVO) {
        DemoTableRespVO demoTableRespVO = demoTableService.update(demoTableReqVO);
        return Answer.success("修改成功", demoTableRespVO);
    }

    @GetMapping("/{demoTableId}")
    @Operation(summary = "根据id获取测试类", description = "根据id获取测试类")
    public Answer<DemoTableRespVO> getDetailById(@PathVariable Long demoTableId) {
        DemoTableRespVO demoTableRespVO = demoTableService.getDetailById(demoTableId);
        return Answer.success("获取成功", demoTableRespVO);
    }

    @DeleteMapping()
    @Operation(summary = "根据id删除测试类", description = "根据id删除测试类")
    @OperationLog(title = "测试类-根据id删除", businessType = BusinessTypeEnum.DELETE)
    public Answer<Void> deleteByIds(@RequestParam("ids") Long[] ids) {
        demoTableService.deleteByIds(ids);
        return Answer.success("删除成功");
    }
}

